<?php
/* @var $this ContentController */
/* @var $model Content */
/* @var $form CActiveForm */
?>

<div class="form">
<?php 
$fieldsStr = isset($model->type) ? $model->type->fields : 'id,name,anons,alias,category_id,metatitle,metakey,metadesc,file';
$fields = explode(',',$fieldsStr); 
?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'gallery-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Поля с <span class="required">*</span> должны быть заполнены.</p>
	<?php echo $form->errorSummary($model); ?>

	<div class="tabs">
		<a href="#tab_<?php echo Yii::app()->params->language; ?>" class="tab active"><?php echo Yii::app()->params->language; ?></a>
		<?php foreach(Yii::app()->params->languages as $key => $value): ?>
			<a href="#tab_<?php echo $key; ?>" class="tab"><?php echo $key; ?></a>
		<?php endforeach;?>
	</div>
	
	<div id="tab_<?php echo Yii::app()->params->language; ?>" class="screen visible">
	<?php if(in_array('name', $fields) ) :?>
		<div class="row">
			<?php echo $form->labelEx($model,'name'); ?>
			<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>1000)); ?>
			<?php echo $form->error($model,'name'); ?>
		</div>
	<?php endif; ?>
	<?php if(in_array('alias', $fields) ) :?>
		<div class="row">
			<?php echo $form->labelEx($model,'alias'); ?>
			<?php echo $form->textField($model,'alias',array('size'=>60,'maxlength'=>255)); ?>
			<?php echo $form->error($model,'alias'); ?>
		</div>
	<?php endif; ?>
	<?php if(in_array('category_id', $fields) ) :?>
		<div class="row">
			<?php echo $form->labelEx($model,'category_id'); ?>
			<?php echo $form->dropDownList($model,'category_id',CSelect::items('CategoryGallery'),  array('empty' => ('Выберите категорию'))); ?>
			<?php echo $form->error($model,'category_id'); ?>
		</div>
	<?php endif; ?>
	<?php if(in_array('anons', $fields) ) :?>
		<div class="row">
			<?php echo $form->labelEx($model,'anons'); ?>
			<?php echo $form->textArea($model,'anons'); ?>
			<?php echo $form->error($model,'anons'); ?>
		</div>
	<?php endif; ?>
	<?php if(in_array('file', $fields) ) :?>
		<div class="row">
			<?php echo $form->labelEx($model,'file'); ?>
			<?php $this->widget('ext.elfinder.ServerFileInput', array(
				        'model' => $model,
				        'attribute' => 'file',
				        'connectorRoute'=>CHtml::normalizeUrl(array('site/fileManager')),
			        )
				); ?>
			<?php echo $form->error($model,'file'); ?>
		</div>
	<?php endif; ?>
	<?php if(in_array('metatitle', $fields) ) :?>
		<div class="row">
			<?php echo $form->labelEx($model,'metatitle'); ?>
			<?php echo $form->textField($model,'metatitle',array('size'=>60,'maxlength'=>1000)); ?>
			<?php echo $form->error($model,'metatitle'); ?>
		</div>
	<?php endif; ?>
	<?php if(in_array('metakey', $fields) ) :?>
		<div class="row">
			<?php echo $form->labelEx($model,'metakey'); ?>
			<?php echo $form->textField($model,'metakey',array('size'=>60,'maxlength'=>1000)); ?>
			<?php echo $form->error($model,'metakey'); ?>
		</div>
	<?php endif; ?>
	<?php if(in_array('metadesc', $fields) ) :?>
		<div class="row">
			<?php echo $form->labelEx($model,'metadesc'); ?>
			<?php echo $form->textField($model,'metadesc',array('size'=>60,'maxlength'=>1000)); ?>
			<?php echo $form->error($model,'metadesc'); ?>
		</div>
	<?php endif; ?>
	</div>
	<?php 
	$lns = Yii::app()->params->languages; 
	$names = isset($model->lns) ? CHtml::listData($model->lns, 'ln', 'name') : array();
	$anons = isset($model->lns) ? CHtml::listData($model->lns, 'ln', 'anons') : array();
	$metatitle = isset($model->lns) ? CHtml::listData($model->lns, 'ln', 'metatitle') : array();
	$metakey = isset($model->lns) ? CHtml::listData($model->lns, 'ln', 'metakey') : array();
	$metadesc = isset($model->lns) ? CHtml::listData($model->lns, 'ln', 'metadesc') : array();
	foreach($lns as $key => $value) : 
	?>
	<div id="tab_<?php echo $key; ?>" class="screen">
		<?php if(in_array('name', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'name'); ?>
				<?php echo $form->textField($model,'[lns]['.$key.']name',array('size'=>60,'maxlength'=>255, 'value'=> isset($names[$key]) ? $names[$key] : '' )); ?>
				<?php echo $form->error($model,'name'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('anons', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'anons'); ?>
				<?php echo $form->textArea($model,'[lns]['.$key.']anons', array('value'=> isset($anons[$key]) ? $anons[$key] : '' )); ?>
				<?php echo $form->error($model,'anons'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('metatitle', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'metatitle'); ?>
				<?php echo $form->textField($model,'[lns]['.$key.']metatitle',array('size'=>60,'maxlength'=>255, 'value'=> isset($metatitle[$key]) ? $metatitle[$key] : '' )); ?>
				<?php echo $form->error($model,'metatitle'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('metakey', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'metakey'); ?>
				<?php echo $form->textField($model,'[lns]['.$key.']metakey',array('size'=>60,'maxlength'=>255, 'value'=> isset($metadesc[$key]) ? $metadesc[$key] : '' )); ?>
				<?php echo $form->error($model,'metakey'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('metadesc', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'metadesc'); ?>
				<?php echo $form->textField($model,'[lns]['.$key.']metadesc',array('size'=>60,'maxlength'=>255, 'value'=> isset($names[$key]) ? $names[$key] : '' )); ?>
				<?php echo $form->error($model,'metadesc'); ?>
			</div>
		<?php endif; ?>
	</div>
	<?php endforeach;?>
<?php $this->endWidget(); ?>

</div><!-- form -->